#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define FILE_NAME "arena"
#define fre 1
using namespace std;
typedef long long ll;

int main(){
#ifdef fre
    freopen(FILE_NAME ".in","r",stdin);
    freopen(FILE_NAME ".out","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int tmp;
        cin>>tmp;
    }
    for(int i=1;i<=m;i++){
        int tmp;
        cin>>tmp;
    }
    int k=0;
    while(pow(2,k)<n){
        k++;
    }
    for(int i=1;i<=k;i++){
        for(int j=1;j<=pow(2,k-i);j++){
            char tmp;
            cin>>tmp;
        }
    }
    int T;
    cin>>T;
    for(int i=1;i<=T;i++){
        srand(time(0)*random()*rand());
        srand(time(0)*random()*rand());
        cout<<rand()%(n*n)+1<<endl;
    }
#ifdef fre
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}